package com.february.todo.MyCalendar;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.february.todo.tools.Bean_todo;
import com.february.todo.R;
import com.february.todo.base.adapter.BaseRecyclerAdapter;
import com.february.todo.tools.ColorSwitcher;


public class SimpleTodoListAdapter extends BaseRecyclerAdapter<Bean_todo> implements View.OnLongClickListener{
    Context context;

    private RecyclerViewOnItemLongClickListener onItemLongClickListener;

    /*设置长按事件*/
    public void setOnItemLongClickListener(RecyclerViewOnItemLongClickListener onItemLongClickListener) {
        this.onItemLongClickListener = onItemLongClickListener;
    }

    @Override
    public boolean onLongClick(View v) {
        int t= (Integer)v.getTag();
        return onItemLongClickListener != null && onItemLongClickListener.onItemLongClickListener(v, (Integer) v.getTag());
    }

    public interface RecyclerViewOnItemLongClickListener {
        boolean onItemLongClickListener(View view, int todoID);
    }

    public SimpleTodoListAdapter(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new itemViewHolder(mInflater.inflate(R.layout.item_simple_todo_list, parent, false));
    }

    @Override
    protected void onBindViewHolder(RecyclerView.ViewHolder holder, Bean_todo item, int position) {
        itemViewHolder h=(itemViewHolder) holder;
        h.timeStart.setText(item.getTimeStart());
        h.timeEnd.setText(item.getTimeEnd());
        h.state.setBackgroundResource(new ColorSwitcher(item.getState()).colorResource);
        h.title.setText(item.getTitle());
        h.line_background.setTag(item.getId());
        h.line_background.setOnLongClickListener(this);
    }

    private static class itemViewHolder extends RecyclerView.ViewHolder {
        TextView timeStart;
        TextView timeEnd;
        TextView state;
        TextView title;
        LinearLayout line_background;
        private itemViewHolder(View itemView) {
            super(itemView);
            timeStart = itemView.findViewById(R.id.time_start);
            timeEnd = itemView.findViewById(R.id.time_end);
            state = itemView.findViewById(R.id.state);
            title = itemView.findViewById(R.id.title);
            line_background=itemView.findViewById(R.id.line_background);
        }
    }
}
